package org.gruposp2p.aularest.server.resource;

import java.io.File;
import java.net.URL;
import java.util.logging.Logger;
import org.gruposp2p.aularest.utils.AulaLogger;
import org.restlet.data.MediaType;
import org.restlet.data.Status;
import org.restlet.representation.FileRepresentation;
import org.restlet.representation.Representation;
import org.restlet.representation.Variant;
import org.restlet.resource.Get;
import org.restlet.resource.ResourceException;
import org.restlet.resource.ServerResource;

/**
 *
 * @author jj
 */
public class MainPageResource extends ServerResource {

    private static final Logger logger =
            AulaLogger.getLogger(MainPageResource.class.getName());

       /**
    * @GET
    */
    @Get
    public Representation represent(Variant variant) throws ResourceException {
        FileRepresentation fileRepresentation = null;
        try {
            URL url = MainPageResource.class.getClassLoader().getResource("index.html");
            System.out.println("url.toURI(): " + url.toURI());
            File file = new File(url.toURI());
            fileRepresentation =
                    new  FileRepresentation(file, MediaType.TEXT_HTML);
        } catch(Exception ex) {
            throw new ResourceException(Status.SERVER_ERROR_INTERNAL, ex);
        }
        return fileRepresentation;
    }
}
